setwd("C:/Users/yuxua/Documents/careers/DEL intern/data deposit/Sandboxes/US")
library(haven)
library(dplyr)
library(janitor)

Jul2020 <- read_sav("C:/Users/yuxua/Documents/careers/DEL intern/data deposit/Sandboxes/US/Jul2020/UCL_DEL_Sandbox_US_Wave2_client.sav")
Sep2021 <- read_sav("C:/Users/yuxua/Documents/careers/DEL intern/data deposit/Sandboxes/US/Sep2021/UCL_DEL_Sandbox_US_Sep2021_client.sav")

names(Jul2020)
names(Sep2021)

US_comp <- compare_df_cols(Jul2020, Sep2021)

#change weighting variable name
Jul2020 <- Jul2020 %>%
  rename(Weight = WeightSandboxW2)
Sep2021 <- Sep2021 %>%
  rename(Weight = WeightSandbox)

###Jul2020

#recode variables
Jul2020 <- Jul2020 %>%
  mutate(intcon = intcon-1,
         conshould = conshould-1)
Jul2020 <- Jul2020 %>%
  mutate(across(conspirx_1:conspirx_5, ~  . -1),
         across(g1wash_p:g12wash_fn, ~  . -1))

table(Jul2020$intcon)
table(Jul2020$conshould)
table(Jul2020$conspirx_1)
table(Jul2020$conspirx_2)
table(Jul2020$conspirx_3)
table(Jul2020$conspirx_4)
table(Jul2020$conspirx_5)
table(Jul2020$g9mat_p)

table(Sep2021$inputstate)
table(Sep2021$tinputstate)

write_sav(Jul2020, "UCL_DEL_Sandbox_US_Wave2_client_new.sav")
write_sav(Sep2021, "UCL_DEL_Sandbox_US_Sep2021_client_new.sav")

Jul2020a <- read_sav("C:/Users/yuxua/Documents/careers/DEL intern/data deposit/Sandboxes/US/Jul2020/UCL_DEL_Sandbox_US_Wave2_client_new.sav")
Sep2021a <- read_sav("C:/Users/yuxua/Documents/careers/DEL intern/data deposit/Sandboxes/US/Sep2021/UCL_DEL_Sandbox_US_Sep2021_client_new.sav")

table(Jul2020a$intcon)
table(Jul2020a$conshould)
table(Jul2020a$conspirx_1)
table(Jul2020a$conspirx_2)
table(Jul2020a$conspirx_3)
table(Jul2020a$conspirx_4)
table(Jul2020a$conspirx_5)
table(Jul2020a$g12wash_fn)

names(Jul2020a)
names(Sep2021a)

Sep2021b <- read_sav("C:/Users/yuxua/Documents/careers/DEL intern/data deposit/Sandboxes/US/Sep2021/UCL_DEL_Sandbox_US_Sep2021_client_race.sav")
names(Sep2021b)

Sep2021b <- Sep2021b %>%
  rename(Weight = WeightSandbox)
write_sav(Sep2021b, "UCL_DEL_Sandbox_US_Sep2021_client_race_new.sav")

############### remove tinputstate from Sep2021
Sep2021 <- read_sav("C:/Users/yuxua/Documents/careers/DEL intern/data deposit/Sandboxes/US/Sep2021/UCL_DEL_Sandbox_US_Sep2021_client_new.sav")
names(Sep2021)

Sep2021 <- Sep2021 %>%
  select(-tinputstate)

Sep2021b <- read_sav("C:/Users/yuxua/Documents/careers/DEL intern/data deposit/Sandboxes/US/Sep2021/UCL_DEL_Sandbox_US_Sep2021_client_race_new.sav")
Sep2021b <- Sep2021b %>%
  select(-tinputstate)

write_sav(Sep2021, "UCL_DEL_Sandbox_US_Sep2021_Data.sav")
write_sav(Sep2021b, "UCL_DEL_Sandbox_US_Sep2021_Data_race.sav")

Feb2020 <- read_sav("C:/Users/yuxua/Documents/careers/DEL intern/data deposit/Sandboxes/US/wave1 feb2020/UCL_DEL_Sandbox_US_Wave1_client 2.sav")
Jul2020a <- read_sav("C:/Users/yuxua/Documents/careers/DEL intern/data deposit/Sandboxes/US/Jul2020/UCL_DEL_Sandbox_US_Wave2_client_new.sav")

US_comp <- compare_df_cols(Feb2020, Jul2020a)

Feb2020 <- Feb2020 %>%
  rename(Weight = WeightSandboxW1,
         track1_1 = track1_w1_1,
         track1_2 = track1_w1_2,
         track1_3 = track1_w1_3,
         track1_4 = track1_w1_4,
         track1_5 = track1_w1_5,
         track1_6 = track1_w1_6,
         track1_7 = track1_w1_7,
         track1_8 = track1_w1_8,
         track1_9 = track1_w1_9,
         track1_10 = track1_w1_10,
         track7 = track7_w1)

names(Feb2020)
write_sav(Feb2020, "UCL_DEL_Sandbox_US_Wave1_client.sav")
